layui.define(['table', 'form'], function (exports) {
    var $ = layui.$
        , form = layui.form
        , table = layui.table
        , setter = layui.setter
        , admin = layui.admin
        , dropdown = layui.dropdown;
    var renderTable;
    var field = '';
    var colsArr;

    var tableTitle;
    var tableField; //表头字段
    var tableSearch = [];//全局搜索条件
    var tableHead;//表头字段


    tableRender();

    function tableRender() {
        colsArr = [
            {field: '', title: '序号', width: 40, type: 'numbers'},
            {
                field: 'reservationNumber', title: '预约单号', align: 'center', templet: function (d) {
                    if (d.nowStatus > 2 && d.nowStatus < 8) {
                        return `<div><a style="color: #00a0e9" href="javascript:void(0);" lay-event="details" class="layui-font-cyan">` + d.reservationNumber + `</div>`
                    } else {
                        return `<span class="layui-font-red">` + d.reservationNumber + `</span>`
                    }

                }
            },
            {field: 'supplierNumber', title: '供应商编码', align: 'center'},
            {field: 'supplierName', title: '供应商', align: 'center'},
            {field: 'estimatedArrivalTime', title: '预约时间', align: 'center'},
            {field: 'gdsNumber', title: '订货数量', align: 'center'},
            {
                field: 'timeoutStatus', title: '超时状态', align: 'center', templet: function (d) {
                    if (d.nowStatus == 7 && d.timeoutStatus == 2) {
                        return `<span style="color: #b52c26" class="layui-font-red">迟到</span>`
                    } else if (d.nowStatus == 7 && d.timeoutStatus == 0) {
                        return `<span style="color: #00be67;" class="layui-font-green">准时</span>`
                    } else if (d.nowStatus == 7 && d.timeoutStatus == 1) {
                        return `<span style="color: #ffbf66" class="layui-font-blue">早到</span>`
                    } else {
                        return `<span style="color: #4d6878" class="layui-font-blue">暂未到达</span>`
                    }
                }
            },
            {
                title: '重新分配', align: 'center', templet: function (d) {
                    if (d.nowStatus < 5 && d.nowStatus > 2 && d.isReassign == 1) {
                        return `<div><a style="color: #00a0e9" href="javascript:void(0);" lay-event="reallocation" class="layui-font-gray">已重新分配</div>`
                    } else if (d.nowStatus < 5 && d.nowStatus > 2) {
                        return `<div><a style="color: #00be67" href="javascript:void(0);" lay-event="reallocation" class="layui-font-blue">点击分配</div>`
                    } else {
                        return `<span style="color: #ffbf66" class="layui-font-red">暂无法重新分配</span>`
                    }
                }
            },
            {fixed: 'right', title: '审批预约', align: 'center', toolbar: '#checkReservation'},
        ]


        layui.each(colsArr, function (inx, val) {
            field += val.hasOwnProperty('field') ? val.field : '';
            field += ',';

            tableHead += val.hasOwnProperty('field') ? val.field : '';
            tableHead += ',';

            tableTitle += val.hasOwnProperty('title') ? (val.hide ? '' : val.title + ',') : ',';

            tableField += val.hasOwnProperty('field') ? (val.hide ? '' : val.field + ',') : ',';
        })

        field = field.substring(field.indexOf(',') + 1, field.length - 2);
        loadTable(colsArr);
    }

    setInterval(() => {
        admin.req({
            url: setter.host + '/reservation/receiveManager/getAllMessage'
            , type: 'get'
            , contentType: "application/json; charset=utf-8"
            , done: function (res) {
                console.log(res)
                if (res.code === 0 && res.msg !== "没有新消息") {
                    let datas = res.data
                    if (datas.length === 1) {
                        // console.log(datas[0].msg.search("预约被取消了请及时")!==-1)
                        if (datas[0].msg.search("预约被取消了请及时") !== -1) {
                            layer.open({
                                content: datas[0].msg
                                , btn: ['关闭']
                            })
                            return false
                        }
                        layer.open({
                            content: datas[0].msg
                            , btn: ['关闭']

                        });
                        renderTable.reload()
                    } else {
                        let msg = ''
                        for (let o of datas) {
                            msg += `${o.msg}\n`
                        }
                        layer.open({
                            title: "收到了多条信息",
                            content: msg
                            , btn: ['关闭']
                        })
                        renderTable.reload()
                    }

                }
            }
        });
    }, 5000)

    function loadTable() {
        var tableWhere = {};
        tableWhere.headField = field;

        renderTable = table.render({
            elem: '#LAY-reservation-list',
            limit: 15,
            limits: [15, 30, 50],
            cols: [colsArr],
            height: 'full-100',
            page: true, //开启分页
            method: 'get',
            cache: false,
            url: '/unite_platform/reservation/receiveManager/getAllReservation'
            , text: {
                none: '暂无相关数据'
            },
            // parseData:function (res){
            //     console.log(res)
            //     return{
            //         "code":res.code,
            //         "msg":res.msg,
            //         "count":res.data.length,
            //         "data":res.data
            //     }
            // }
        });

        //监听行工具事件
        table.on('tool(LAY-reservation-list)', function (obj) {
            //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                , layEvent = obj.event; //获得 lay-event 对应的值
            switch (layEvent) {
                case "confirm":
                    layer.open({
                        type: 2
                        , title: '确认预约'
                        , content: setter.host + '/confirm'
                        , area: ['720px', '590px']
                        , btn: ['确定', '取消']
                        , success: function (editFrame, index) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                                , subBody = editFrame.find('iframe').contents();
                            new Promise(function (resolve, reject) {
                                admin.req({
                                    url: setter.host + `/reservation/supplier/getBoxamount`
                                    , type: 'post'
                                    , header: {"Content-Type": "application/x-www-form-urlencoded"}
                                    , data: {
                                        "reservationNumber": data.reservationNumber
                                    }
                                    , done: function (res) {
                                        if (res.code === 0) {
                                            resolve(res.data)
                                        } else {
                                            layer.msg("获取托盘错误")
                                        }

                                        data.orders.map(item => {
                                            console.log(item)
                                            subBody.find("#orderNumbers").append(`<input type="text" value="${item.orderNumber}"  id="${item.orderNumber}" readonly autocomplete="off" class="layui-input">`)
                                            subBody.find(`#${item.orderNumber}`).val(`${item.orderNumber}`)
                                        })

                                        // data.drivers.map(item=>{
                                        let ind = 0
                                        for (let item of data.drivers) {
                                            ind++
                                            // console.log(item)

                                            subBody.find("#cars").append(`
                                        <label class="layui-form-label">车辆信息：</label>
                                        <input type="hidden" name="carId[]" value="${item.id}" >

                                        <div class="layui-form-item">
                                          <label class="layui-form-label">车型</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.carType}" id="carType" readonly autocomplete="off" class="layui-input">
                                          </div>
                                       </div>
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">车长</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.carLength}" id="carLength" readonly autocomplete="off" class="layui-input">
                                          </div>
                                        </div>
                                    
                                    
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">分配月台</label>
                                          <div class="layui-input-inline" >
                                            <input type="hidden" name="estimatedPlatformNumber"  id="estimatedPlatformNumber" readonly autocomplete="off" class="layui-input">
                                            <select name="confirmPlatformNumber[]" id="platform" lay-filter="platform" lay-verify="required"  >
                                              <option value="请选择" >请选择</option>

                                            </select>
                                          </div>
                                        </div>
                                    
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">分配收货员</label>
                                          <div class="layui-input-inline" >
                                            <input type="hidden" name="estimatedReceiverNumber" id="estimatedReceiverNumber"  autocomplete="off" class="layui-input" >
                                            <select name="confirmReceiverNumber[]" id="receiver" lay-filter="receiver" lay-verify="required">
                                              <option value="请选择" >请选择</option>
                                            </select>
                                          </div>
                                        </div>
                                        `)
                                        }

                                    }
                                });
                            }).then((res) => {
                                subBody.find("#id").val(data.id)
                                subBody.find("#driverCount").val(data.drivers.length)
                                subBody.find("#reservationNumber").val(data.reservationNumber)
                                subBody.find("#driverNumber").val(data.driverNumber)
                                subBody.find("#supplierNumber").val(data.supplierNumber)
                                subBody.find("#supplierName").val(data.supplierName)
                                subBody.find("#gdsCount").val(data.gdsCount)
                                subBody.find("#gdsNumber").val(data.gdsNumber)
                                subBody.find("#orderNumber").val(data.orderNumber)
                                subBody.find("#estimatedArrivalTime").val(data.estimatedArrivalTime)
                                subBody.find("#confirmArrivalTime").val(data.estimatedArrivalTime)
                                subBody.find("#confirmOverTime").val(data.confirmOverTime)
                                subBody.find("#trayCount").val(res)


                                // if ($("#confirmArrivalTime").val() !== "" && $("#durationTime").val() !== "请选择") {
                                //     layui.admin.req({
                                //         url: setter.host + '/reservation/receiveManager/freePlatformByTime'
                                //         , type: 'post'
                                //         , contentType: "application/x-www-form-urlencoded"
                                //         , data: {
                                //             startTime: $("#confirmArrivalTime").val(),
                                //             keepTime: Number($("#durationTime").val())
                                //         }
                                //         , done: function (res) {
                                //             //请求成功后
                                //             if (res.code == 0) {
                                //                 $(`[id=platform] option`).remove()
                                //                 for (let r of res.data) {
                                //                     if (r.sure === 1) {
                                //                         subBody.find(`[id=platform]`).append(`<option value="${r.platformNumber}">${r.platformCode}</option>`)
                                //                         // $(`[id=platform]`).append(`<option value="${r.platformNumber}">${r.platformCode}</option>`)
                                //                     } else {
                                //                         subBody.find(`[id=platform]`).append(`<option disabled="disabled" value="${r.platformNumber}">${r.platformCode}</option>`)
                                //                         // $(`[id=platform]`).append(`<option disabled="disabled" value="${r.platformNumber}">${r.platformCode}</option>`)
                                //                     }
                                //                 }
                                //                 layui.form.render('select');
                                //             } else {
                                //                 layer.msg(res.msg);
                                //             }
                                //         }
                                //     })
                                //
                                //
                                //     layui.admin.req({
                                //         url: setter.host + '/reservation/receiveManager/freeReceiverByTime'
                                //         , type: 'post'
                                //         , contentType: "application/x-www-form-urlencoded"
                                //         , data: {
                                //             startTime: $("#confirmArrivalTime").val(),
                                //             keepTime: Number($("#durationTime").val())
                                //         }
                                //         , done: function (res) {
                                //             $(`[id =receiver] option`).remove()
                                //             if (res.code == 0) {
                                //                 for (let r of res.data) {
                                //                     if (r.sure === 1) {
                                //                         subBody.find("[id=receiver]").append(`<option value="${r.receiverNumber}">${r.receiverName}</option>`)
                                //                         // $(`[id=receiver]`).append(`<option value="${r.receiverNumber}">${r.receiverName}</option>`)
                                //                     } else {
                                //                         subBody.find("[id=receiver]").append(`<option disabled="disabled" value="${r.receiverNumber}">${r.receiverName}</option>`)
                                //                         // $(`[id=receiver]`).append(`<option disabled="disabled" value="${r.receiverNumber}">${r.receiverName}</option>`)
                                //                     }
                                //                 }
                                //                 layui.form.render('select');
                                //             } else {
                                //                 layer.msg(res.msg);
                                //             }
                                //         }
                                //     })
                                // }

                            })

                        }
                        , yes: function (index, layero) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                                , submitID = 'LAY-menu-edit-submit'
                                , submit = layero.find('iframe').contents().find('#' + submitID);
                            //监听提交
                            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                                let playload = data.field
                                console.log(playload)
                                // let plats=[]
                                // let reces=[]
                                // let index = 0
                                //
                                //
                                // while (true){
                                //     if(playload[`confirmReceiverNumber[${index}]`]==""||playload[`confirmReceiverNumber[${index}]`]==undefined||playload[`confirmReceiverNumber[${index}]`]==null) break
                                //     reces.push(playload[`confirmReceiverNumber[${index}]`])
                                //     index++
                                // }
                                // index = 0
                                // while (true){
                                //     if(playload[`confirmPlatformNumber[${index}]`]==""||playload[`confirmPlatformNumber[${index}]`]==undefined||playload[`confirmPlatformNumber[${index}]`]==null) break
                                //     plats.push(playload[`confirmPlatformNumber[${index}]`])
                                //     index++
                                // }
                                // let pre = plats.filter((e, i) => plats.indexOf(e) !== plats.lastIndexOf(e) && plats.indexOf(e) === i)
                                // let rre = reces.filter((e, i) => reces.indexOf(e) !== reces.lastIndexOf(e) && reces.indexOf(e) === i)
                                // if(pre.length>0){
                                //     layer.msg(`月台选择重复`);
                                //     return false
                                // }
                                // if(rre.length>0){
                                //     layer.msg(`收货员选择重复`);
                                //     return false
                                // }

                                admin.req({
                                    url: setter.host + `/reservation/receiveManager/confirmReservation/${playload.reservationNumber}`
                                    , type: 'post'
                                    , dataType: 'json'
                                    , contentType: "application/json; charset=utf-8"
                                    , data: JSON.stringify(playload)
                                    , done: function (res) {
                                        if (res.code === 0 && res.msg === "预约单确认成功") {
                                            table.reload('LAY-reservation-list');
                                            layer.msg(res.msg);
                                            layer.close(index);
                                        }
                                    }

                                });
                            });
                            submit.trigger('click');
                        }
                    });

                    break;
                case "cancel":
                    admin.req({
                        url: setter.host + `/reservation/receiveManager/cancelReservation`
                        , type: 'post'
                        , data: {"reservationNumber": data.reservationNumber}
                        , done: function (res) {
                            if (res.code === 0 && res.msg === "预约取消成功") {
                                table.reload('LAY-reservation-list');
                                layer.msg(res.msg);
                            }
                        }
                    });
                    break;
                // case "chidao":
                //     layer.open({
                //         type: 2
                //         ,title: '迟到重新分配'
                //         ,content: setter.host+'/chidao'
                //         ,area: ['720px', '590px']
                //         ,btn: ['重新分配', '取消']
                //         ,success:function(editFrame,index){
                //             var iframeWindow = window['layui-layer-iframe'+ index]
                //                 ,subBody = editFrame.find('iframe').contents();
                //             console.log("一行数据",data)
                //             let timeoutCount = 0
                //             for(let item of data.drivers){
                //                 if(item.timeoutStatus == 2){
                //                     timeoutCount++
                //                     subBody.find("#cars").append(`
                //                         <label class="layui-form-label">车辆信息：</label>
                //                         <input type="hidden" name="carId[]" value="${item.id}" >
                //
                //                         <div class="layui-form-item">
                //                           <label class="layui-form-label">车型</label>
                //                           <div class="layui-input-inline" >
                //                             <input type="text"  value="${item.carType}" id="carType" readonly autocomplete="off" class="layui-input">
                //                           </div>
                //                        </div>
                //                         <div class="layui-form-item">
                //                           <label class="layui-form-label">车长</label>
                //                           <div class="layui-input-inline" >
                //                             <input type="text"  value="${item.carLength}" id="carLength" readonly autocomplete="off" class="layui-input">
                //                           </div>
                //                         </div>
                //
                //
                //                         <div class="layui-form-item">
                //                           <label class="layui-form-label">分配月台</label>
                //                           <div class="layui-input-inline" >
                //                             <input type="hidden" name="estimatedPlatformNumber"  id="estimatedPlatformNumber" readonly autocomplete="off" class="layui-input">
                //                             <select name="confirmPlatformNumber[]" id="platform" lay-verify="required"  >
                //                               <option value="${item.carLength}" >${item.acPlatform.platformCode}</option>
                //                             </select>
                //                           </div>
                //                         </div>
                //
                //                         <div class="layui-form-item">
                //                           <label class="layui-form-label">分配收货员</label>
                //                           <div class="layui-input-inline" >
                //                             <input type="hidden" name="estimatedReceiverNumber" id="estimatedReceiverNumber"  autocomplete="off" class="layui-input" >
                //                             <select name="confirmReceiverNumber[]" id="receiver" lay-verify="required">
                //                                 <option value="${item.Receiver}" >${item.acReceiver.receiverName}</option>
                //                             </select>
                //                           </div>
                //                         </div>
                //                         `)
                //                 }
                //
                //             }
                //
                //             subBody.find("#id").val(data.id)
                //             subBody.find("#driverCount").val(timeoutCount)
                //             subBody.find("#reservationNumber").val(data.reservationNumber)
                //             subBody.find("#driverNumber").val(data.driverNumber)
                //             subBody.find("#supplierNumber").val(data.supplierNumber)
                //             subBody.find("#supplierName").val(data.supplierName)
                //             subBody.find("#gdsCount").val(Number(data.gdsCount))
                //             subBody.find("#gdsNumber").val(Number(data.gdsNumber))
                //             subBody.find("#confirmArrivalTime").val(data.confirmArrivalTime)
                //             subBody.find("#durationTime").val(Number(data.confirmOverTime))
                //             subBody.find("#trayCount").val(data.trayCount)
                //
                //
                //         }
                //             //提交修改月台和收货员信息的url
                //         ,yes: function(index, layero){
                //             var iframeWindow = window['layui-layer-iframe'+ index]
                //                 ,submitID = 'LAY-menu-edit-submit'
                //                 ,submit = layero.find('iframe').contents().find('#'+ submitID);
                //             //监听提交
                //             iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                //                 let playload=data.field
                //                 console.log(playload)
                //                 $.ajax({
                //                     url:setter.host+`/reservation/receiveManager/changePlatform`
                //                     ,type:"POST"
                //                     ,data:JSON.stringify(playload)
                //                     ,contentType:"application/json; charset=utf-8"
                //                     ,dataType:"json"
                //                     ,success:function (res){
                //                         if(res.code === 0 && res.msg==="重新分配月台成功"){
                //                             table.reload('LAY-reservation-list');
                //                             layer.msg(res.msg);
                //                             layer.close(index);
                //                         }
                //                     }
                //                 })
                //             });
                //             submit.trigger('click');
                //         }
                //     });
                //     break
                // case "zaodao":
                //     layer.open({
                //         type: 2
                //         ,title: '早到'
                //         ,content: setter.host+'/confirm'
                //         ,area: ['720px', '590px']
                //         ,btn: ['确定', '取消']
                //         ,success:function(editFrame,index){
                //             var iframeWindow = window['layui-layer-iframe'+ index]
                //                 ,subBody = editFrame.find('iframe').contents();
                //             subBody.find("#id").val(data.id)
                //             subBody.find("#reservationNumber").val(data.reservationNumber)
                //             subBody.find("#driverNumber").val(data.driverNumber)
                //             subBody.find("#supplierNumber").val(data.supplierNumber)
                //             subBody.find("#orderNumber").val(data.orderNumber)
                //             subBody.find("#confirmArrivalTime").val(data.estimatedTimeOfArrival)
                //         }
                //         //提交修改月台和收货员信息的url
                //         ,yes: function(index, layero){
                //             var iframeWindow = window['layui-layer-iframe'+ index]
                //                 ,submitID = 'LAY-menu-edit-submit'
                //                 ,submit = layero.find('iframe').contents().find('#'+ submitID);
                //             //监听提交
                //             iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                //                 let playload=data.field
                //                 console.log(playload)
                //                 admin.req({
                //                     url: setter.host+`/reservation/receiveManager/changePlatform`
                //                     ,type:'post'
                //                     ,header:{"Content-Type":"application/x-www-form-urlencoded"}
                //                     ,dataType:'json'
                //                     ,contentType: "application/json; charset=utf-8"
                //                     ,data:JSON.stringify(playload)
                //                     ,done: function(res){
                //                         if(res.code === 0 && res.msg==="预约单确认成功"){
                //                             table.reload('LAY-reservation-list');
                //                             layer.msg(res.msg);
                //                             layer.close(index);
                //                         }
                //                     }
                //
                //                 });
                //             });
                //             submit.trigger('click');
                //         }
                //     });
                //     break
                // case "checkPlatform":
                //     layer.open({
                //         type: 1
                //         ,title: '月台详情'
                //         ,content: '<div class="layui-container" style="width: 98%"><table id="LAY-human-gzjl" lay-filter="LAY-human-gzjl" class=""></table></div>'
                //         ,shadeClose: true//开启遮罩关闭
                //         ,area: ['70%', '90%']
                //         ,maxmin: true
                //         ,btn: ['确定']
                //         ,success: function(layero, index){
                //             table.render({
                //                 elem: '#LAY-human-gzjl'  // 弹出层表格id
                //                 ,url: setter.host + '/human/menu/getGongzuo' // 后端请求URL地址
                //                 ,method: 'post'
                //                 ,where: {'platformNumber':data.id}
                //                 ,page: true
                //                 ,contentType:"application/json; charset=utf-8"
                //                 ,cols: [[
                //                     {field: 'platformNumber', title: '月台编号',sort:true,align:'center',hide:true},
                //                     {field: 'platformCode', title: '月台号',sort:true,align:'center'},
                //                     {field: 'platformIsUse', title: '是否正在使用',sort:true,align:'center',width: 100, sort: true,templet: function(d){
                //                             if(d.platformIsUse ==0){return '未使用'}
                //                             else if(d.platformIsUse==1){return '正在使用'}
                //                         }},
                //                 ]]
                //             })
                //         }
                //         ,yes: function(index, layero){
                //             layer.close(index)
                //         }
                //     });
                //     break;
                // case "checkReceiver":
                //     layer.open({
                //         type: 1
                //         ,title: '售货员详情'
                //         ,content: '<div class="layui-container" style="width: 98%"><table id="LAY-human-gzjl" lay-filter="LAY-human-gzjl" class=""></table></div>'
                //         ,shadeClose: true//开启遮罩关闭
                //         ,area: ['70%', '90%']
                //         ,maxmin: true
                //         ,btn: ['确定']
                //         ,success: function(layero, index){
                //             table.render({
                //                 elem: '#LAY-human-gzjl'  // 弹出层表格id
                //                 ,url: setter.host + '/human/menu/getGongzuo' // 后端请求URL地址
                //                 ,method: 'post'
                //                 ,where: {'headField':'gz_start,gz_over,gz_bumen,gz_gangwei','user_id':data.id}
                //                 ,page: true
                //                 ,contentType:"application/json; charset=utf-8"
                //                 ,cols: [[
                //                     {field: 'gz_start', title: '开始日期',sort:true,align:'center'},
                //                     {field: 'gz_over', title: '结束日期',sort:true,align:'center'},
                //                     {field: 'gz_bumen', title: '部门',sort:true,align:'center',width: 100, sort: true,},
                //                     {field: 'gz_gangwei', title: '岗位',align:'center',sort:true,sort: true,width: 130,},
                //                 ]]
                //             })
                //         }
                //         ,yes: function(index, layero){
                //             layer.close(index)
                //         }
                //     });
                //     break;
                // case "checkDriver":
                //     layer.open({
                //         type: 1
                //         ,title: '司机详情'
                //         ,content: '<div class="layui-container" style="width: 98%"><table id="LAY-human-gzjl" lay-filter="LAY-human-gzjl" class=""></table></div>'
                //         ,shadeClose: true//开启遮罩关闭
                //         ,area: ['70%', '90%']
                //         ,maxmin: true
                //         ,btn: ['确定']
                //         ,success: function(layero, index){
                //             table.render({
                //                 elem: '#LAY-human-gzjl'  // 弹出层表格id
                //                 ,url: setter.host + '/human/menu/getGongzuo' // 后端请求URL地址
                //                 ,method: 'post'
                //                 ,where: {'headField':'gz_start,gz_over,gz_bumen,gz_gangwei','user_id':data.id}
                //                 ,page: true
                //                 ,contentType:"application/json; charset=utf-8"
                //                 ,cols: [[
                //                     {field: 'gz_start', title: '开始日期',sort:true,align:'center'},
                //                     {field: 'gz_over', title: '结束日期',sort:true,align:'center'},
                //                     {field: 'gz_bumen', title: '部门',sort:true,align:'center',width: 100, sort: true,},
                //                     {field: 'gz_gangwei', title: '岗位',align:'center',sort:true,sort: true,width: 130,},
                //                 ]]
                //             })
                //         }
                //         ,yes: function(index, layero){
                //             layer.close(index)
                //         }
                //     });
                //     break;
                case "reallocation":
                    layer.open({
                        type: 2
                        , title: '收货员及月台重新分配'
                        , content: setter.host + '/reallocation'
                        , area: ['720px', '590px']
                        , btn: ['重新分配', '取消']
                        , success: function (editFrame, index) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                                , subBody = editFrame.find('iframe').contents();
                            console.log("一行数据", data)
                            let timeoutCount = 0
                            for (let item of data.drivers) {
                                if (item.nowStatus > 2 && item.nowStatus < 5) {
                                    timeoutCount++
                                    subBody.find("#cars").append(`
                                        <label class="layui-form-label">车辆信息：</label>
                                        <input type="hidden" name="carId[]" value="${item.id}" >

                                        <div class="layui-form-item">
                                          <label class="layui-form-label">车型</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.carType}" id="carType" readonly autocomplete="off" class="layui-input">
                                          </div>
                                       </div>
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">车长</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.carLength}" id="carLength" readonly autocomplete="off" class="layui-input">
                                          </div>
                                        </div>
                                    
                                    
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">分配月台</label>
                                          <div class="layui-input-inline" >
                                            <input type="hidden" name="estimatedPlatformNumber"  id="estimatedPlatformNumber" readonly autocomplete="off" class="layui-input">
                                            <select name="confirmPlatformNumber[]" id="platform" lay-verify="required"  >
                                              <option value="${item.carLength}" >${item.acPlatform.platformCode}</option>
                                            </select>
                                          </div>
                                        </div>
                                    
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">分配收货员</label>
                                          <div class="layui-input-inline" >
                                            <input type="hidden" name="estimatedReceiverNumber" id="estimatedReceiverNumber"  autocomplete="off" class="layui-input" >
                                            <select name="confirmReceiverNumber[]" id="receiver" lay-verify="required">
                                                <option value="${item.Receiver}" >${item.acReceiver.receiverName}</option>
                                            </select>
                                          </div>
                                        </div>
                                        `)
                                } else {
                                    subBody.find("#cars").append(`<label class="layui-form-label">当前状态无法重新分配</label>`)
                                }

                            }

                            subBody.find("#id").val(data.id)
                            subBody.find("#driverCount").val(timeoutCount)
                            subBody.find("#reservationNumber").val(data.reservationNumber)
                            subBody.find("#driverNumber").val(data.driverNumber)
                            subBody.find("#supplierNumber").val(data.supplierNumber)
                            subBody.find("#supplierName").val(data.supplierName)
                            subBody.find("#gdsCount").val(Number(data.gdsCount))
                            subBody.find("#gdsNumber").val(Number(data.gdsNumber))
                            subBody.find("#confirmArrivalTime").val(data.confirmArrivalTime)
                            subBody.find("#durationTime").val(Number(data.confirmOverTime))
                            subBody.find("#trayCount").val(data.trayCount)


                        }
                        //提交修改月台和收货员信息的url
                        , yes: function (index, layero) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                                , submitID = 'LAY-menu-edit-submit'
                                , submit = layero.find('iframe').contents().find('#' + submitID);
                            //监听提交
                            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                                let playload = data.field
                                console.log(playload)
                                $.ajax({
                                    url: setter.host + `/reservation/receiveManager/changePlatform`
                                    , type: "POST"
                                    , data: JSON.stringify(playload)
                                    , contentType: "application/json; charset=utf-8"
                                    , dataType: "json"
                                    , success: function (res) {
                                        if (res.code === 0 && res.msg === "重新分配成功") {
                                            table.reload('LAY-reservation-list');
                                            layer.msg(res.msg);
                                            layer.close(index);
                                        }
                                    }
                                })
                            });
                            submit.trigger('click');
                        }
                    });
                    break
                case "details":
                    layer.open({
                        type: 2
                        , title: '预约详情'
                        , content: setter.host + '/details'
                        , area: ['720px', '590px']
                        , btn: ['关闭']
                        , success: function (editFrame, index) {
                            var iframeWindow = window['layui-layer-iframe' + index]
                                , subBody = editFrame.find('iframe').contents();
                            console.log("一行数据", data)
                            let timeoutCount = 0
                            for (let item of data.drivers) {
                                timeoutCount++
                                subBody.find("#cars").append(`
                                        <label class="layui-form-label">车辆信息：</label>
                                        <input type="hidden" name="carId[]" value="${item.id}" >

                                        <div class="layui-form-item">
                                          <label class="layui-form-label">车型</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.carType}" id="carType" readonly autocomplete="off" class="layui-input">
                                          </div>
                                       </div>
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">车长</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.carLength}" id="carLength" readonly autocomplete="off" class="layui-input">
                                          </div>
                                        </div>
                                    
                                    
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">分配月台</label>
                                          <div class="layui-input-inline" >
                                            <input type="text"  value="${item.acPlatform.platformCode}" id="carLength" readonly autocomplete="off" class="layui-input">
                                          </div>
                                        </div>
                                    
                                        <div class="layui-form-item">
                                          <label class="layui-form-label">分配收货员</label>
                                          <div class="layui-input-inline" >
                                          <input type="text"  value="${item.acReceiver.receiverName}" id="carLength" readonly autocomplete="off" class="layui-input">
                                          </div>
                                        </div>
                                        `)

                            }

                            subBody.find("#id").val(data.id)
                            subBody.find("#driverCount").val(timeoutCount)
                            subBody.find("#reservationNumber").val(data.reservationNumber)
                            subBody.find("#driverNumber").val(data.driverNumber)
                            subBody.find("#supplierNumber").val(data.supplierNumber)
                            subBody.find("#supplierName").val(data.supplierName)
                            subBody.find("#gdsCount").val(Number(data.gdsCount))
                            subBody.find("#gdsNumber").val(Number(data.gdsNumber))
                            subBody.find("#confirmArrivalTime").val(data.confirmArrivalTime)
                            subBody.find("#durationTime").val(Number(data.confirmOverTime))
                            subBody.find("#trayCount").val(data.trayCount)


                        }
                        //提交修改月台和收货员信息的url
                        // ,yes: function(index, layero){
                        //     var iframeWindow = window['layui-layer-iframe'+ index]
                        //         ,submitID = 'LAY-menu-edit-submit'
                        //         ,submit = layero.find('iframe').contents().find('#'+ submitID);
                        //     //监听提交
                        //     iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                        //         let playload=data.field
                        //         console.log(playload)
                        //         $.ajax({
                        //             url:setter.host+`/reservation/receiveManager/changePlatform`
                        //             ,type:"POST"
                        //             ,data:JSON.stringify(playload)
                        //             ,contentType:"application/json; charset=utf-8"
                        //             ,dataType:"json"
                        //             ,success:function (res){
                        //                 if(res.code === 0 && res.msg==="重新分配月台成功"){
                        //                     table.reload('LAY-reservation-list');
                        //                     layer.msg(res.msg);
                        //                     layer.close(index);
                        //                 }
                        //             }
                        //         })
                        //     });
                        //     submit.trigger('click');
                        // }
                    });
                    break
            }

            console.log(obj)

        });
    }

    $('.layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });


    var active = {
        batchdel: function () {
            var checkData = renderTable.checkStatus()
            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }
            layer.prompt({
                formType: 1
                , title: '敏感操作，请验证当前用户口令'
            }, function (value, index_prompt) {
                var command = layui.sessionData('layuiSession').command;
                if (value == command) {
                    layer.close(index_prompt);
                    layer.confirm('确定删除吗？', function (index_confirm) {
                        layer.close(index_confirm);
                        //因为是单选项，只能选择一个
                        if (checkData[0].hasOwnProperty('children')) {
                            layer.confirm('该选择的删除数据有子菜单,确定都删除吗?', {icon: 3, title: '提示'}, function (index_del) {
                                layer.close(index_del);
                                del(checkData[0].menuId, checkData[0].pId);
                            });
                        } else {
                            del(checkData[0].menuId, checkData[0].pId);
                        }
                    });
                } else {
                    layer.msg('口令错误');
                }
            });
        }
        , add: function () {
            var obj = {};
            obj.bakUrl = setter.host + '/human/menu/toMenuList';
            obj.jsType = 'add';
            layui.common.postUrl(obj, setter.host + '/human/menu/toInsert');
        }
        , edit: function () {
            var checkData = renderTable.checkStatus();
            if (checkData.length > 1) {
                return layer.msg('只能选中编辑一行');
            }
            if (checkData.length === 0) {
                return layer.msg('请选择一行数据进行编辑');
            }
            layer.open({
                type: 2
                , title: '编辑菜单'
                , content: setter.host + '/human/menu/toEdit'
                , area: ['720px', '590px']
                , btn: ['确定', '取消']
                , success: function (editFrame, index) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , subBody = editFrame.find('iframe').contents();
                    var type = checkData[0].type;
                    subBody.find("#id").val(checkData[0].id)
                }
                , yes: function (index, layero) {
                    var iframeWindow = window['layui-layer-iframe' + index]
                        , submitID = 'LAY-menu-edit-submit'
                        , submit = layero.find('iframe').contents().find('#' + submitID);
                    //监听提交

                    console.log(iframeWindow, submitID, submit)
                    iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                        console.log(JSON.stringify(data.field))
                        admin.req({
                            url: setter.host + '/human/menu/upUser'
                            , type: 'post'
                            , dataType: 'json'
                            , contentType: "application/json; charset=utf-8"
                            , data: JSON.stringify(data.field)
                            , done: function (res) {
                                //请求成功后
                                if (res.status == setter.response.statusCode.status_Success) {
                                    if (data.field.pId == '-1' || data.field.toChangePid == '-1') {
                                        loadTable(colsArr, field);
                                    } else {
                                        renderTable.refresh(data.field.pId);
                                        //如果更新的菜单与当前修改的父菜单不一样，那么还需要刷新新修改后的菜单
                                        if (data.field.toChangePid != '' && data.field.pId != data.field.toChangePid) {
                                            renderTable.refresh(data.field.toChangePid);
                                        }
                                    }
                                }
                                layer.close(index);
                                layer.msg(res.msg);
                            }
                        });
                    });
                    submit.trigger('click');
                }
            });
        }
    }

    function del(menuId, pId) {
        var indexLoad = layer.msg('删除菜单，请稍后', {
            icon: 16
            , shade: 0.01
        });
        admin.req({
            url: setter.host + '/adminmanager/menu/batchdelMenu'
            , type: 'post'
            , contentType: "application/json; charset=utf-8"
            , data: '{"menuId":"' + menuId + '","pId":"' + pId + '"}'
            , done: function (res) {
                //请求成功后
                if (res.status == setter.response.statusCode.status_Success) {
                    if (pId == '-1') {
                        loadTable(colsArr, field);
                    } else {
                        renderTable.refresh(pId);
                    }
                }
                layer.close(indexLoad);
                layer.msg(res.msg);
            }
        });
    }

    form.on('submit(LAY-human-normal-search)', function (data) {
        let search = {};

        search.key = data.field.whereKey;
        search.value = data.field.whereValue;

        console.log(data)
        renderTable.reload({
            url: setter.host + `/reservation/receiveManager/filterTable`,
            method: "post",
            where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                search: search //查询字段
            }
        });
    });

    //对外暴露的接口
    exports('select', {});
});